#include "stdafx.h"
#include "OthersQuWu.h"

#include "conio.h"

OthersQuWu::OthersQuWu()
{
	picID = IDB_QUWU;
//	picID = IDB_CLASS2_MIDVALUE;


	resetBitMap();
}

OthersQuWu::~OthersQuWu()
{

}

COLORREF OthersQuWu::getLowestColor(CImage *image, int x, int y)
{
	COLORREF color;
	unsigned int tmp = 0;;
	color = image->GetPixel(x, y);

	for (int i = 0; i < 3; i++) {
		int cB = (color >> (i * 8)) & 0xff;
		tmp = tmp > cB ? tmp : cB;
	}
	color = (tmp << 16) | (tmp << 8) | tmp;

	return color;
}

COLORREF OthersQuWu::getBetterColor(CImage *image, int x, int y)
{
	COLORREF color;
	unsigned int mid = 0;;
	color = image->GetPixel(x, y);
	unsigned int picColor[3];

	for (int i = 0; i < 3; i++) {
		picColor[i] = (color >> (i * 8)) & 0xff;
		mid += picColor[i];
	}

	mid = mid / 3;

	for (int i = 0; i < 3; i++) {
		int sub = (picColor[i] - mid);
		int tmp;

		/*
		if (sub > 1 || sub < -1) {
			tmp = sub * 20;
		}
		else {
			tmp = 0;
		}
		*/
		tmp = sub * 5;

		picColor[i] = (tmp + picColor[i] - 50) & 0xff;
	}

	color = (picColor[0]) | (picColor[1] << 8) | (picColor[2] << 16);

	return color;
}

void OthersQuWu::drawPics(CDC* pDC)
{
	CDC cdc;
	COLORREF color;
	CImage srcimage, destimage;

	BITMAP srcInfo;

	srcBitMap.GetBitmap(&srcInfo);

	CopyBitmap(&srcBitMap, &destBitMap);

	cbitMapToImage(&srcimage, &srcBitMap);
	cbitMapToImage(&destimage, &destBitMap);

	int width, height;

	for (width = 0; width < srcInfo.bmWidth - 1; width++) {
		for (height = 0; height < srcInfo.bmHeight - 1; height++) {
			color = getBetterColor(&srcimage, width, height);
			destimage.SetPixel(width, height, color);
		}
	}

	int x = srcInfo.bmWidth;
	int y = srcInfo.bmHeight;

	cdc.CreateCompatibleDC(pDC);
	cdc.SelectObject(&destBitMap);
	pDC->StretchBlt(30, 20, x, y, &cdc, 0, 0, x, y, SRCCOPY);
}

